import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as actions from '../actions/index'
import Top from './Top/Top'
import List from './List/List'

class Home extends Component {

    componentDidMount() {
        if(!this.props.list || !this.props.list.length) {
            this.props.get_List()
        }
    }

    pushBtn() {
        this.props.history('/approval')
    }

    render() { 
        let { list } = this.props
        return (
            <div className='Home'>
                <Top pushBtn={this.pushBtn.bind(this)} />
                <List list={list} />
            </div>
        )
    }
}

let mapStateToProps = ({dataReducer}) => {
    return {
        ...dataReducer
    }
}

let mapDispatchToProps = (dispatch) => bindActionCreators(actions, dispatch)
 
export default connect(mapStateToProps, mapDispatchToProps)(Home)